package hospital;

import java.io.*; 
import java.net.*; 

class severTCP { 

  public static void main(String argv[]) throws Exception 
    { 
      String fraseCliente; 
      ServerSocket socketRecepcao = new ServerSocket(6789); 
      Banco b = new Banco();
    
      while(true) { 
  
           Socket socketConexao = socketRecepcao.accept();
           System.out.println("Conectou");
           ObjectInputStream vindoDoCliente = new ObjectInputStream(socketConexao.getInputStream());
           ObjectOutputStream paraOcliente = new ObjectOutputStream(socketConexao.getOutputStream());
           
           Message men = (Message)vindoDoCliente.readObject();
    	   fraseCliente = men.getData();

// teste Neto - System.out.println( men.getCommand() + " | " + men.getData() );

           // Alterado por Neto - if (men.getCommand().equals("Consulta") ) {
           if (men.getData().equals("Consulta") ) {
                    System.out.println("Consulta");
                    String retorno[] = b.ConsultaView(); 
                    for (int i = 0; i < retorno.length; i++) {
                    	men.setData(retorno[i] + '\n');
					}
           }
           else {
        	   if (men.getCommand().equals("low")) {
        		   men.setData(fraseCliente.toLowerCase() + "hehehehe" + '\n') ;
        	   }
           }
           
           paraOcliente.writeObject(men);
        } 
      } 
  } 
